import { createRouter, createWebHashHistory } from 'vue-router'

const routes = [
  // 商城
  {
    path: '/',
    component: () => import('../views/index.vue'),
  },
  {
    path: '/product',
    component: () => import('../views/product.vue'),
  },
  {
    path: '/address',
    component: () => import('../views/address.vue'),
  },

  // 期货
  {
    path: '/forward/index',
    component: () => import('../views/forward/index.vue'),
  },
  {
    path: '/forward/gu',
    component: () => import('../views/forward/gu.vue'),
  },
  {
    path: '/forward/profit',
    component: () => import('../views/forward/profit.vue'),
  },
  {
    path: '/forward/withdraw',
    component: () => import('../views/forward/withdraw.vue'),
  },
  {
    path: '/forward/market',
    component: () => import('../views/forward/market.vue'),
  },
  {
    path: '/forward/rank',
    component: () => import('../views/forward/rank.vue'),
  },

  // 登录注册
  {
    path: '/login',
    component: () => import('../views/login.vue'),
  },
  {
    path: '/register',
    component: () => import('../views/register.vue'),
  },
]

const router = createRouter({
  routes,
  history: createWebHashHistory(),
  scrollBehavior(to, from, savedPosition) {
    if (to.hash) {
      return {
        el: to.hash,
      }
    } else if (savedPosition) {
      return savedPosition
    } else {
      return { top: 0 }
    }
  },
})

export default router
